package com.movitech.wechat;

import com.gson.WeChat;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Authentication extends HttpServlet
{
  private static final long serialVersionUID = 1L;
  private static String Token = "weixin1234567890";

  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException
  {
    String outPut = "error";
    String signature = req.getParameter("signature");
    String timestamp = req.getParameter("timestamp");

    String nonce = req.getParameter("nonce");
    String echostr = req.getParameter("echostr");

    if (WeChat.checkSignature(Token, signature, timestamp, nonce).booleanValue()) {
      outPut = echostr;
    }
    PrintWriter out = resp.getWriter();
    out.write(outPut);
    out.close();
    out = null;
  }
}